<template>
    <div>
      <div class="goods-list" >
        <div class="goods-item" v-for="item in goodsList" :key="item.id" @click="goDetail(item.id)">
          <img :src="item.picUrl">
          <h1 class="goods-title">
            {{item.name}}
          </h1>
          <div class="goods-info">
            <div class="price">
              <span class="new">￥{{item.retailPrice}}</span>
              <span class="old">￥{{item.counterPrice}}</span>
            </div>
            <div class="sell">
              <span class="hot">热卖中</span>
              <span class="save">剩{{item.sortOrder}}件</span>
            </div>
          </div>
        </div>
        <mt-button type="danger" size="large" plain @click="getMore">加载更多</mt-button>
      </div>
    </div>
</template>

<script>
  import { getGoods } from '@/api/api'


  export default {
    name: 'goodList',
    data() {
      return {
        pageNo:1,
        pageSize:10,
        goodsList:[]
      }
    },
    created () {
      this.createGoods();
    },
    methods: {
      // createGoods() {
      //   getGoods(this.pageindex)
      //     .then(res=>{
      //       this.goodsList = this.goodsList.concat(res.data.message);
      //       console.log("返回的状态：{}",this.goodsList.concat(res.data.message));
      //       console.log("查询的列表：{}",this.goodsList);
      //     })
      // },
      createGoods(){
         var $this=this;
        this.axios({
        method:'get',
        url: "http://localhost:8083/goods/list",
        params:{pageNo:this.pageNo,pageSize:this.pageSize}
      }).then(function(res){
          console.log(res);
          $this.goodsList=res.data.obj.list;
      });
      },
      getMore() {
        this.pageNo++;
        this.createGoods();
        
      },
      goDetail(id) {
        this.$router.push("/home/goodsinfo/"+id)
        // this.$router.push({path:"/home/goodsinfo/"+id})
        // this.$router.push({name:'goodsinfo',params:{id:id}})
      }
    }
  }
</script>

<style scoped lang="scss">
  .goods-list {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    padding: 7px;
    .goods-item {
      width: 49%;
      border: 1px solid #ccc;
      box-shadow: 0 0 5px #ccc;
      margin-bottom: 10px;
      padding:2px;
      display: flex;
      flex-direction: column;
      justify-content: space-between;
      min-height: 290px;
      img{
        width: 100%;
      }
      .goods-title {
        font-size: 14px;
        padding:0 2px;
      }
      .goods-info {
        background-color: #eee;
        padding:0 5px;
        .price {
          .new {
            color: red;
            font-size: 16px;
            margin-right: 10px;
          }
          .old {
            color: #bbb;
            text-decoration: line-through;
            font-size: 12px;
          }
        }
        .sell {
          margin: 3px;
          font-size: 12px;
          color: #8f8f94;
          display: flex;
          justify-content: space-between;
        }
      }
    }
  }
</style>
